<!DOCTYPE html>
<html>
  <head>
    <title>WebRTC Local Network Discovery</title>
  </head>
  <body>
    <h1>WebRTC Local Network Discovery</h1>
    <script>
      const peerConnection = new RTCPeerConnection({
        iceServers: [] // 不使用外部 ICE 服务器
      });

      // 监听 ICE 候选项，输出找到的本地候选地址
      peerConnection.onicecandidate = function(event) {
        if (event.candidate) {
          console.log("Found ICE candidate:", event.candidate.candidate);
        }
      };

      // 创建并发送 offer 请求，开始 ICE 连接过程
      async function startDiscovery() {
        try {
          const offer = await peerConnection.createOffer();
          await peerConnection.setLocalDescription(offer);
          console.log("Created offer:", offer);
        } catch (error) {
          console.error("Error creating offer:", error);
        }
      }

      startDiscovery();
    </script>
  </body>
</html>
